package com.zxx.cascommon.base.result;

import org.springframework.util.StringUtils;

/**
 * 统一返回结果工具类
 *
 * @author zhoukai
 * @date 2019/6/15 11:49
 */
public class ResultUtils {

    public static Result success(Object object) {
        return new Result(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getName(), object);
    }

    public static Result success() {
        return new Result(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getName());
    }

    public static Result fail(Object object) {
        return new Result(ResultEnum.FAIL.getCode(), ResultEnum.FAIL.getName(), object);
    }

    public static Result rateLimiterError(Object object) {
        return new Result(ResultEnum.REQUEST_RATE_LIMIT.getCode(), ResultEnum.REQUEST_RATE_LIMIT.getName(), object);
    }

    public static Result tokenError(Object object) {
        return new Result(ResultEnum.TOKEN_ERROR.getCode(), ResultEnum.TOKEN_ERROR.getName(), object);
    }

    public static Result tokenExpired(Object object) {
        return new Result(ResultEnum.TOKEN_EXPIRED.getCode(), ResultEnum.TOKEN_EXPIRED.getName(), object);
    }

    public static Result paramsError(Object object) {
        return new Result(ResultEnum.PARAMS_ERROR.getCode(), ResultEnum.PARAMS_ERROR.getName(), object);
    }

    public static Result internalError(Object object) {
        return new Result(ResultEnum.INTERNAL_ERROR.getCode(), ResultEnum.INTERNAL_ERROR.getName(), object);
    }

    public static Result noChange(String message) {
        if (!StringUtils.isEmpty(message)) {
            message = ResultEnum.DATA_NO_CHANGE.getName();
        }
        return new Result(ResultEnum.DATA_NO_CHANGE.getCode(), message);
    }

    public static Result dataAlreadyExist(String message) {
        if (!StringUtils.isEmpty(message)) {
            message = ResultEnum.DATA_ALREADY_EXIST.getName();
        }
        return new Result(ResultEnum.DATA_ALREADY_EXIST.getCode(), message);
    }

    public static Result dataNotExit(String message) {
        if (!StringUtils.isEmpty(message)) {
            message = ResultEnum.DATA_NOT_EXIST.getName();
        }
        return new Result(ResultEnum.DATA_NOT_EXIST.getCode(), message);
    }

    public static Result passwordError(String message) {
        if (!StringUtils.isEmpty(message)) {
            message = ResultEnum.PASSWORD_ERROR.getName();
        }
        return new Result(ResultEnum.PASSWORD_ERROR.getCode(), message);
    }
}
